package org.example.JVM.ByteCode.Type.CONSTANT;

import org.example.JVM.ByteCode.Type.CpInfo;
import org.example.JVM.ByteCode.Type.U1;
import org.example.JVM.ByteCode.Type.U2;

import java.nio.ByteBuffer;

/**
 * @description:存储方法句柄，为实现动态调用invokedynamic指令增加的常量结构
 * @author: farprt
 * @create: 2022-11-13 15:55
 **/
public class CONSTANT_MethodHandle_info extends CpInfo {

    //取值范围1-9，表示方法句柄的类型
    private U1 reference_kind;
    //指向常量池的某个常量索引
    private U2 reference_index;

    public CONSTANT_MethodHandle_info(U1 tag) {
        super(tag);
    }

    @Override
    public void read(ByteBuffer codeBuf) throws Exception {
        reference_kind = new U1(codeBuf.get());
        reference_index = new U2(codeBuf.get(), codeBuf.get());
    }
}